package com.itheima.d7_tcp4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class SocketMultiTask implements Runnable{
    private Socket socket;

    public SocketMultiTask() {
    }

    public SocketMultiTask(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try (Socket accept = this.socket;) {
            // 3、从socket通信管道中得到一个字节输入流。
            final InputStream is = accept.getInputStream();

            // 4、把原始的字节输入流包装成高效的输入流
            final BufferedReader br = new BufferedReader(new InputStreamReader(is));

            // 5、使用数据输入流读取客户端发送过来的消息
            final String result = br.readLine();
            System.out.println(result);

            System.out.println("当前处理来自线程: " + Thread.currentThread().getName());

            br.close();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
